<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/10/10 17:14
 * Desc:
 */
class Model_Api_V2_Product_Seeding
{

    /**
     * 推荐
     * @param $seed
     * @param $tag_word
     * @return array
     */
    public static function recommend($seed, $tag_word = '')
    {
        $type_id = $seed['typeid'];
        if (!in_array($type_id, array(4, 101, 115))) {
            $basefiled = "a.id,a.title,a.price,a.litpic,a.satisfyscore,a.ishidden,b.displayorder";
        } else {
            $basefiled = "a.id,a.litpic,a.ishidden,b.displayorder";
        }
        $model = DB::select('maintable')
            ->from('model')
            ->where('id', '=', $type_id)
            ->execute()
            ->get('maintable');
        $sql   = "SELECT " . $basefiled . " FROM sline_" . $model . " AS a LEFT JOIN `sline_allorderlist` b ON (a.id=b.aid and b.typeid=" . $type_id . ") ";
        $sql   .= "WHERE a.ishidden=0 ";
        if ($seed['kind'] != 1 && $tag_word) {
            $sql .= "AND tagword='" . $tag_word . "' ";
        }
        $sql .= "ORDER BY IFNULL(b.displayorder,9999) ASC,a.modtime DESC,a.addtime DESC ";
        $sql .= "LIMIT 0,10";
        return DB::query(1, $sql)->execute()->as_array();
    }
}